<?php

header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
?>

<link href="//cdn.rawgit.com/Eonasdan/bootstrap-datetimepicker/e8bddc60e73c1ec2475f827be36e1957af72e2ea/build/css/bootstrap-datetimepicker.css" rel="stylesheet"/>

 <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css"/>

<?php
require_once  __DIR__ . '/includes/authenticate.php';

if(isset($_POST['noteid'])){

$noteID = $_POST['noteid'];	

include_once './db_bb_connect.php';

//////////////////////////////////////////////

$sql = "SELECT * FROM profiles
WHERE ID = '$noteID'";

$result = $db->query($sql);
$row = $result->fetch_assoc();

$content = $row['content'];
$category = $row['category'];
$playerID = $row['playerID'];
$date = $row['date'];

//////////////////////////////////////////////

$sql2 = "SELECT firstname, lastname
FROM users 
WHERE user_key = '$playerID'";

$result2 = $db->query($sql2);
$row2 = $result2->fetch_assoc();

$firstname = $row2['firstname']; 
$lastname = $row2['lastname']; 
  
?>
<br><br><br>
<div class="container-fluid">
<div class="row">
<div class="col-md-2"> </div>
<div class="col-md-8" id="updatestatus">

<div class="text-center"><h3>Edit Player Note of <?= $firstname; ?> <?= $lastname; ?> </h3></div>

<form method="POST" action="">
 <div class="form-group">
<select class="form-control" name="category">
         	<option value="<?= $category; ?>" selected="selected"><?= ucfirst($category); ?></option>
         	<option value="personal">Personal</option>
         	<option value="fundamentals">Fundamentals</option>
         	<option value="training">Training</option>
         	<option value="game">Game</option>
         	<option value="injuries">Injuries</option>
</select>
<br>

       
            <div class='input-group date datetimepicker9' id='datetimepicker9'>
                <input type='text' class="form-control" name="date" value="<?= $date; ?>"/>
                <span class="input-group-addon">
                    <span class="glyphicon glyphicon-calendar">
                    </span>
                </span>
            </div>
       

<input type="hidden" name="noteid" value="<?= $noteID; ?>"/>

<br>
 <textarea class="form-control" rows="4" name="content" ><?= $content; ?></textarea> 
<br><br>

	<button type="submit" class="btn btn-default"> Update Entry </button>
 </div>
</form>
</div>
<div class="col-md-2"> </div>
</div>
</div>



<?php } ?>

<script type="text/javascript" src="//code.jquery.com/jquery-2.1.1.min.js"></script>
  <!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 

 <script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment-with-locales.js"></script>

 <script src="//cdn.rawgit.com/Eonasdan/bootstrap-datetimepicker/e8bddc60e73c1ec2475f827be36e1957af72e2ea/src/js/bootstrap-datetimepicker.js"></script>

<script type="text/javascript">
 
$("form").on("submit", function(e) {
    postData = $(this).serialize();
    $.ajax({
        type: "POST",
        url: "./includes/handlers/playerprofile_editnote_handler.php",
        data: postData,
        success: function(data) { 
            $("#updatestatus").html('Note of <?= $firstname; ?> <?= $lastname; ?> has been updated!'); 
        },
        error: function (xhr, status, error) {
            alert(xhr.responseText + status + error);
        }
      }); 
    e.preventDefault();
});  

$(function () {
  $('.datetimepicker9').datetimepicker({
    viewMode: 'years',
    format: 'YYYY-MM-DD'
  });
});

</script>

